package com.own.component.common.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.own.base.BaseResponseCode;
import com.own.component.common.em.RequestEnum;
import com.own.component.common.exception.BusinessException;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * ExceptionMessageModel
 *
 * @author chenxueli
 * @date 2020/8/18 9:59
 */
@Schema(title = "错误返回结果类")
@Getter
@Setter
@ToString
public final class ExceptionMessageModel extends BaseResponseModel {

    @Schema(title = "错误内容")
    @JsonInclude(JsonInclude.Include.NON_DEFAULT)
    private String ex;

    public ExceptionMessageModel(BaseResponseCode responseCode) {
        this(responseCode, responseCode.desc());
    }

    public ExceptionMessageModel(BaseResponseCode responseCode, String messageEx) {
        super(responseCode);
        this.ex = messageEx;
        super.setSuccess(false);
    }

    public ExceptionMessageModel(BusinessException e) {
        super(e.getCode(), e.getMessage());
        this.ex = e.getMessage();
        super.setSuccess(false);
    }

    public ExceptionMessageModel(RuntimeException e) {
        super(RequestEnum.FAILURE.code(), e.getMessage());
        this.ex = e.getMessage();
        super.setSuccess(false);
    }

    public ExceptionMessageModel(String code, String message, String messageEx) {
        super(code, message);
        this.ex = messageEx;
        super.setSuccess(false);
    }

    public ExceptionMessageModel() {
        this(RequestEnum.FAILURE);
    }

    public ExceptionMessageModel(String messageEx) {
        this(RequestEnum.FAILURE, messageEx);
    }

}
